package com.ybu.controller;

import com.ybu.common.Constants;
import com.ybu.common.JwtUtils;
import com.ybu.common.R;
import com.ybu.pojo.vo.UserLoginVO;
import com.ybu.pojo.vo.OrderVO;
import com.ybu.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("api/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    @GetMapping("list")
    public R<List<OrderVO>> getOrderList(HttpServletRequest request){
        String token = request.getHeader(Constants.TOKEN_HEADER);
       UserLoginVO userLoginVO = JwtUtils.parseToken(token);
        List<OrderVO> orderList = orderService.getOrderList(userLoginVO);
        return R.ok(orderList);
    }
}
